package server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Whois {
	public static String GetWhois(String name)
	{
		String content = "";
		String str="";
		try {
			
			URL url = new URL("http://50.19.251.197/whois/whois?name="+name);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setReadTimeout(500000);
			connection.setConnectTimeout(1000000);
			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("utf-8")));
			char[] buf = new char[102102];
			int numRead=0;
	        while((numRead=reader.read(buf)) != -1){
	            String readData = String.valueOf(buf, 0, numRead);
	            content += readData;
	            buf = new char[102102];
	        }
	        reader.close();
            Document doc = Jsoup.parse(content); 
         
            str  = doc.select("body").html();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return str;
	}
}
